﻿using System;
using System.Collections.Generic;
using System.Data;
using T.FAS.Runtime.Metadata.Entity;
using T.ServiceComponent.DAC.Service;

namespace T.FAS.Runtime.Action.Dao
{
    public class ActionMetaDataLogic : DaoService<ActionMetaData>, IActionMetaDataDao
    {
        IActionMetaDataDao actionMetaDataDao = DaoFactory.GetDaoFactory<IActionMetaDataDao>().Instance;

        public List<ActionMetaData> GetActionMetaDataByFilter(Dictionary<string, string> filter)
        {
            return actionMetaDataDao.GetActionMetaDataByFilter(filter);
        }

        public ActionMetaData GetActionMetaDataByID(string actionID)
        {
            return actionMetaDataDao.GetActionMetaDataByID(actionID);
        }

        public void AddActionMetaData(ActionMetaData actionMetaData)
        {
            actionMetaDataDao.AddActionMetaData(actionMetaData);
        }

        public void UpdateActionMetaData(ActionMetaData actionMetaData)
        {
            actionMetaDataDao.UpdateActionMetaData(actionMetaData);
        }

        public void DeleteActionMetaData(string actionID)
        {
            actionMetaDataDao.DeleteActionMetaData(actionID);
        }

        public int CheckUnique(Dictionary<string, string> filter)
        {
            return actionMetaDataDao.CheckUnique(filter);
        }

        /// <summary>
        /// 保存或修改唯一性验证
        /// </summary>
        /// <param name="action">DB实体</param>
        /// <param name="OpeType">0:新增; 1:修改</param>
        /// <returns>true:表示入参action唯一，可以进行保存; false:表示数据库中存在重复数据，无法保存</returns>
        public bool CheckUnique(ActionMetaData action, int OpeType = 0)
        {
            var filter = new Dictionary<string, string>
            {
                { "Code", action.Code },
            };
            if (OpeType == 1)
            {
                filter["ID"] = action.ID;
            }
            var cnt = actionMetaDataDao.CheckUnique(filter);
            return cnt == 0;
        }
    }
}
